package com.woniu.map.service.impl;

import com.woniu.internalcommon.constant.CommonStatusEnum;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.request.PointRequest;
import com.woniu.internalcommon.response.TraSearchResponse;
import com.woniu.internalcommon.response.TrackResponse;
import com.woniu.map.remote.TrackClient;
import com.woniu.map.service.TrackService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TrackServiceImpl implements TrackService {
    @Resource
    TrackClient trackClient;

    /**
     * 添加轨迹
     * @param tid
     * @param trname
     * @return
     */
    @Override
    public ResponseResult<TrackResponse> addTrack(String tid, String trname) {


        try {
            TrackResponse trackResponse = trackClient.addTrack(tid, trname);
            return ResponseResult.success(trackResponse);
        }catch (Exception e){
            log.info("addTrack 发生异常 "+ e.getMessage());
            return ResponseResult.fail(null)
                    .setCode(CommonStatusEnum.MAP_DISTRICT_ERROR.getCode());
        }
    }

    /**
     * 上传轨迹服务

     */
    @Override
    public ResponseResult<String> uploadTrack(PointRequest pointRequest) {
        try {
            return ResponseResult.success(trackClient.upload(pointRequest)) ;
        }catch (Exception e){

            return ResponseResult.fail(null).setCode(20000);
        }
    }
    /**
     * 查当前时间端轨迹
     * 返回 所用时间(分钟)和多少米
     */
    @Override
    public ResponseResult<TraSearchResponse>   traSearch(String tid, Long startTime, Long endTime){


        try{
            return  ResponseResult.success(trackClient.traSearch(tid,startTime,endTime));
        }catch(Exception e){
            return  ResponseResult.fail(null).setCode(20000);
        }
    }

}
